﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RatingHelper.DAL
{
    public class UserRepository:IUserRepository
    {
        public UserRepository()
        {

        }

        #region IUserRepository Members

        public void Add(UserInfo uInfo)
        {
            db.UserInfos.AddObject(uInfo);
        }

        public void Delete(UserInfo uInfo)
        {
            db.UserInfos.DeleteObject(uInfo);
        }


        public UserInfo GetByAuthority(string userName, string password)
        {

            return db.UserInfos.Single(o => o.PWD == password && string.Equals(o.UName, userName, StringComparison.OrdinalIgnoreCase));
                            
        }

        public IQueryable<UserInfo> GetAllUsers()
        {
            return db.UserInfos;
        }

        public void Save()
        {
            db.SaveChanges();
        }

        #endregion


        #region data fields

        /// <summary>
        /// db entities
        /// </summary>
        RatingHelperDBEntities db = new RatingHelperDBEntities();

        #endregion
    }
}
